package com.android.presenter.info;

import com.android.model.net.HttpObserver;
import com.android.presenter.base.BasePresenter;
import com.android.presenter.iview.IVerifySmsView;
import com.android.model.info.UserModel;
import com.android.model.entity.res.VerifyCodeResult;
import com.android.util.log.LogUtil;

/**
 * author:  TenFace
 * date:    2017/9/27
 * description: 电影页面的业务逻辑处理层
 */

public class VerifyCodePresenter extends BasePresenter<IVerifySmsView> {

    private static final String TAG = VerifyCodePresenter.class.getSimpleName();
    private UserModel mUserModel;

    public VerifyCodePresenter(IVerifySmsView iVerifySmsView) {
        super(iVerifySmsView);
        mUserModel = UserModel.getInstance();
    }

    public void verifySmsCode(String ex55Pin, final String phone, String phoneCode, final String codeType, final String operateType) {
        mUserModel.verifySmsCode(ex55Pin, phone, phoneCode, codeType, operateType, new HttpObserver<VerifyCodeResult>() {
            @Override
            public void onSuccess(VerifyCodeResult verifyCodeResult) {
                LogUtil.e(TAG, "校验验证码成功");
                if (verifyCodeResult != null) {
                    if (mIView != null) {
                        mIView.verifySmsSuccess(verifyCodeResult);
                    }
                }
            }

            @Override
            public void onError(int errType, String errMessage) {
                LogUtil.e(TAG, "失败码：" + errType + "》》信息：" + errMessage);
                if (mIView != null) {
                    mIView.verifySmsFail(errType, errMessage);
                }
            }
        }, mIView.getLifeSubject());
    }

}
